package com.xuptGurantee.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xuptGurantee.system.dto.MatchDto;
import com.xuptGurantee.system.entity.Activity;
import com.xuptGurantee.system.entity.Matcher;
import com.xuptGurantee.system.entity.Volunteer;
import com.xuptGurantee.system.service.ActivityService;
import com.xuptGurantee.system.service.MatchDtoService;
import com.xuptGurantee.system.service.MatcherService;
import com.xuptGurantee.system.service.VolunteerService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zzzhc
 * @version 1.0
 * @description: TODO
 * @date 2022/11/3 10:40
 */
@Service
public class MatchDtoServiceImpl implements MatchDtoService {

    @Resource
    MatcherService matcherService;

    @Resource
    ActivityService activityService;

    @Resource
    VolunteerService volunteerService;

    @Override
    public List<MatchDto> getMatchDtoList(MatchDto matchDto) {
        LambdaQueryWrapper<Activity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Activity::getPublisherId,matchDto.getHandlerId());
        List<Activity> actList = activityService.list(queryWrapper);
        ArrayList<MatchDto> matchDtoList = new ArrayList<>();

        for (Activity act:actList
             ) {
            LambdaQueryWrapper<Matcher> matcherWrapper = new LambdaQueryWrapper<>();
            matcherWrapper.eq(Matcher::getActivityId, act.getId());
            List<Matcher> matcherList = matcherService.list(matcherWrapper);
            for (Matcher mat : matcherList
            ) {
                    MatchDto matDtoItem = new MatchDto();
                    Volunteer vol = volunteerService.getById(mat.getVolunteerId());
                    matDtoItem.setVolunteer(vol);
                    Activity actPro = activityService.getById(mat.getActivityId());
                    matDtoItem.setActivity(actPro);
                    matchDtoList.add(matDtoItem);
            }
        }
        return matchDtoList;
//        LambdaQueryWrapper<Matcher> matcherWrapper = new LambdaQueryWrapper<>();
//        matcherWrapper.eq(Matcher::getVolunteerId, matchDto.getHandlerId());
//        List<Matcher> matcherList = matcherService.list(matcherWrapper);
//        ArrayList<MatchDto> matchDtoList = new ArrayList<>();
//        for (Matcher mat : matcherList
//        ) {
//            if (mat.getVolunteerId().equals(matchDto.getHandlerId())) {
//                MatchDto matDtoitem = new MatchDto();
//                Volunteer vol = volunteerService.getById(mat.getVolunteerId());
//                matDtoitem.setVolunteer(vol);
//                Activity act = activityService.getById(mat.getActivityId());
//                matDtoitem.setActivity(act);
//                matchDtoList.add(matDtoitem);
//            }
//        }
//        return matchDtoList;
    }
}
